<?php include_once 'member_top.php' ;?>
<?php
    $tablename = 'account';
	$action=$_REQUEST['action'];
	switch($action){
	    case 'add':
	 
	    $_POST["member"]=intval($_SESSION["uid"]);
		$sql="insert into $tablename set employeeid=".intval($_POST["employee"]).",productid=".intval($_POST["product"]).",price=".intval($_POST["price"]).",quantity=".intval($_POST["quantity"]).
		",memberid=".intval($_POST["member"]).",dateline='".strtotime($_POST['sellingtime'])."'";
		mysql_query($sql) or die(mysql_error().'<br>'.$sql);
		alert('Buy success');
		gourl('member_buy.php');
		break;
		
		case 'edit':
		$id=$_REQUEST['id'];
		$sql="update $tablename set employeeid=".intval($_POST["employee"]).",productid=".intval($_POST["product"]).",price=".intval($_POST["price"]).",quantity=".intval($_POST["quantity"]).
		",memberid=".intval($_POST["member"]).",dateline='".strtotime($_POST['sellingtime'])."' where id=$id";
		mysql_query($sql) or die(mysql_error().'<br>'.$sql);
		alert('Modify success');
		gourl('account.php');
		break;
		
		case 'del':
		$id=$_REQUEST['id'];
		$sql = "delete from account where id=$id";
		mysql_query($sql) or die(mysql_error().'<br>'.$sql);
		alert('Deleted successful');
		gourl('account.php');
		break;
		
		case 'delall':
		if(count($_POST['checkid'])!=0){
		$del = implode(',', $_POST['checkid']);
		$sql = "delete from account where id in ($del)";
		mysql_query($sql) or die(mysql_error().'<br>'.$sql);
		}
		alert('Batch successful deleted');
		gourl('account.php');
		break;
	}
?>

<?php
    $query=mysql_query("select * from product where show_type!=0");
    $showlist=array();
    $discountlist = array();
    while($value=mysql_fetch_array($query))
    {
        if($value["show_type"]==1)
            $showlist[]=$value;
        else $discountlist[]=$value;
    } 
?>
<div class="centerbg">

  <div class="allbody">
  <div id="scrollDiv">
<ul>
<?php foreach($discountlist as $value){?>
<li><span style="color:white"><?php echo $value["show_title"];?></span>...<a href="javascript:show_window('details','id=<?php echo $value['id']?>')">More</a></li>
<?php } ?>
</ul>

</div>
    <div class="bd">
      <div class="nytitle">
        <div class="fl title">Expense Details</div>
        <div class="fr"><a class="nybutton" href="javascript:show_window('buy','');">Buy Product</a></div>
        <div class="clear"></div>
      </div>
      <div class="biaoge">
        <form id="form" name="form" method="post" action="?action=delall">
          <?php 
		$pagenum = 12;
		
		$akey=$_REQUEST['akey'];
		$w = " id is not null " ;	
		if($akey!=''){
			$query=mysql_query("select product where $w");
		    $w.=" and title like '%".$akey."%' ";
		    $query=mysql_query("select * from product where $w");
		    $idlist="(";
		    while($value=mysql_fetch_array($query))
		    {
		    	$idlist=$idlist . $value["id"].",";
		    }
		    $idlist=substr($idlist,0,strlen($idlist)-1);
		    $idlist=$idlist.")";
		    $w = " id is not null " ;
		    $w=$w." and productid in $idlist";
		}
		$w.=" and memberid=$_SESSION[uid]";
		$w.=" order by id desc ";
		$total = mysql_fetch_array(mysql_query("select Count(*) from $tablename where $w "));
		$total = $total[0];
		if ($total!=0){
		$totalpage = ceil($total / $pagenum);
		if(!isset($_GET['page']) || !intval($_GET['page']) || $_GET['page'] > $totalpage){
			$page = 1;
		}
		else{
			$page = $_GET['page'];
		}
		$query=mysql_query("select * from member");
        $memberlist=array();
        while($value=mysql_fetch_array($query))
        {
	        $memberlist[$value['id']]=$value;
        }

        $query=mysql_query("select * from employee");
        $employeelist=array();
        while($value=mysql_fetch_array($query))
        {
	        $employeelist[$value['id']]=$value;
        }
        $query=mysql_query("select * from product");
        $productlist=array();
        while($value=mysql_fetch_array($query))
        {
	        $productlist[$value['id']]=$value;
        }		
		$startnum=($page-1) * $pagenum;
		$sql = "select * from $tablename where $w limit $startnum, $pagenum";
		$result = mysql_query($sql);
?>
          <table width="832" border="0" cellspacing="1" cellpadding="1" bgcolor="#e34681">
            <tr height="30" bgcolor="#e34681" style="color:#FFF;">
             
              <td width="92" align="left">account ID</td>
              <td width="114" align="left">Member Name</td>
              <td width="114" align="left">Product Name</td>
              <td width="92" align="left">Price</td>
              <td width="92" align="left">Quantity</td>
              <td width="123" align="left">Employeer Name</td>
              <td width="123" align="left">Selling Time</td>
    
            </tr>
            <?php while($row = mysql_fetch_array($result)){?>
            <tr height="30" bgcolor="#FFFFFF">
              
              <td align="left"><?php echo $row['id']?></td>
              <td align="left"><?php echo $memberlist[$row["memberid"]]["m_name"]?></td>
              <td align="left"><?php echo $productlist[$row["productid"]]["title"]?></td>
              <td align="left"><?php echo $row['price']?></td>
              <td align="left"><?php echo $row['quantity']?></td>
              <td align="left"><?php echo $employeelist[$row["employeeid"]]["e_name"]?></td>
              <td align="left"><?php echo date("Y-m-d",$row['dateline']);?></td>
   
            </tr>
            <?php }?>
          </table>
          <div style="text-align:center; padding-top:20px; padding-bottom:10px;"><?php echo  page($page, $totalpage, $pagenum, $total,$urlstring)?></div>

          <?php }else{?>
          <ul>
            <li style="padding:30px;">No information</li>
          </ul>
          <?php }?>
        </form>
      </div>
    </div>
  </div>
  <div id="container">
		<div id="example">
			<div id="slides">
				<div class="slides_container">
				    <?php foreach($showlist as $value){?>
					<div class="slide">
						<h1><?php echo $value["show_title"];?></h1>
						<p><?php echo $value["show_content"];?></p>
					</div>
					<?php } ?>	

				</div>
				<a href="" class="prev"><img src="img/arrow-prev.png" width="24" height="43" alt="Arrow Prev"></a>
				<a href="" class="next"><img src="img/arrow-next.png" width="24" height="43" alt="Arrow Next"></a>
			</div>
			<img src="img/example-frame.png" width="739" height="341" alt="Example Frame" id="frame">
		</div>
	</div>
</div>

<?php include_once 'footer.php' ;?>